home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
CHAP05.ZIP
/
CHAP05
/
PATRON
/
PAGEWIN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-17
|
20KB
|
747 lines
/*
* PAGEWIN.CPP
* Modifications for Chapter 5
*
* Window procedure for the Pages window and support functions. This
* window manages its own scrollbars and viewport and provides
* printing capabilities as well. The public CPages::Print lives here.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "patron.h"
extern HWND g_hDlgPrint;
extern BOOL g_fCancelPrint;
/*
* PagesWndProc
*
* Purpose:
* Window procedure for the Pages window.
*/
LRESULT __export FAR PASCAL PagesWndProc(HWND hWnd, UINT iMsg
, WPARAM wParam, LPARAM lParam)
{
LPCPages ppg;
PAINTSTRUCT ps;
HDC hDC;
int iPos, iTmp;
int iMin, iMax;
UINT idScroll;
ppg=(LPCPages)GetWindowLong(hWnd, PAGEWL_STRUCTURE);
switch (iMsg)
{
case WM_CREATE:
ppg=(LPCPages)((LPCREATESTRUCT)lParam)->lpCreateParams;
SetWindowLong(hWnd, PAGEWL_STRUCTURE, (LONG)ppg);
ppg->m_hWnd=hWnd;
break;
case WM_PAINT:
hDC=BeginPaint(hWnd, &ps);
//Draw only if we have a page to show.
if (0!=ppg->m_cPages)
ppg->Draw(hDC, FALSE, FALSE);
EndPaint(hWnd, &ps);
break;
case WM_HSCROLL:
case WM_VSCROLL:
idScroll=(WM_HSCROLL==iMsg) ? SB_HORZ : SB_VERT;
iPos=GetScrollPos(hWnd, idScroll);
iTmp=iPos;
GetScrollRange(hWnd, idScroll, &iMin, &iMax);
switch (wParam)
{
case SB_LINEUP: iPos -= 20; break;
case SB_PAGEUP: iPos -=100; break;
case SB_LINEDOWN: iPos += 20; break;
case SB_PAGEDOWN: iPos +=100; break;
case SB_THUMBPOSITION:
iPos=ScrollThumbPosition(wParam, lParam);
break;
//We don't want scrolling on this message.
case SB_THUMBTRACK:
return 0L;
}
iPos=max(iMin, min(iPos, iMax));
if (iPos!=iTmp)
{
//Set the new position and scroll the window as necessary.
SetScrollPos(hWnd, idScroll, iPos, TRUE);
if (SB_HORZ==idScroll)
{
ppg->m_xPos=iPos;
ScrollWindow(hWnd, iTmp-iPos, 0, NULL, NULL);
}
else
{
ppg->m_yPos=iPos;
ScrollWindow(hWnd, 0, iTmp-iPos, NULL, NULL);
}
}
break;
default:
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
return 0L;
}
/*
* CPages::Draw
*
* Purpose:
* Paints the current page in the pages window.
*
* Parameters:
* hDC HDC to draw on, could be a metafile or printer DC or
* any other type of DC.
* fNoColor BOOL indicating if we should use screen colors or
* printer colos (B&W). Objects are printed as-is, however.
* This is TRUE for printer DCs or print preview.
* fPrinter BOOL indicating if this is a printer DC in which case
* we eliminate some of the fancy drawing, like shadows on
* the page and so forth.
*
* Return Value:
* None
*/
void CPages::Draw(HDC hDC, BOOL fNoColor, BOOL fPrinter)
{
RECT rc, rcT;
UINT uMM;
HPEN hPen;
HBRUSH hBrush;
HGDIOBJ hObj1, hObj2;
COLORREF cr;
char szTemp[20];
UINT cch;
DWORD dwExt;
//Make sure the DC is in LOMETRIC
uMM=SetMapMode(hDC, MM_LOMETRIC);
if (!fPrinter)
{
/*
* We maintain a 6mm border around the page on the screen besides
* 12.7mm margins. We also have to account for the scroll position
* with m_*Pos which are in pixels so we have to convert them.
*/
SetRect(&rcT, m_xPos, m_yPos, 0, 0);
RectConvertMappings(&rcT, hDC, FALSE);
rc.left = LOMETRIC_BORDER-rcT.left;
rc.top =-LOMETRIC_BORDER-rcT.top;
}
else
{
/*
* We define the corner of the printed paper at a negative
* offset so rc.right and rc.bottom come out right below.
*/
SetRect(&rc, -(int)m_xMarginLeft, m_yMarginTop, 0, 0);
}
rc.right =rc.left+(UINT)m_cx+(UINT)(m_xMarginLeft+m_xMarginRight);
rc.bottom=rc.top -(UINT)m_cy-(UINT)(m_yMarginTop+m_yMarginBottom);
//Draw a rectangle filled with the window color to show the page.
if (!fPrinter)
{
if (fNoColor)
{
//Black frame, white box for printed colors.
hPen =CreatePen(PS_SOLID, 0, RGB(0,0,0));
hBrush=CreateSolidBrush(RGB(255, 255, 255));
}
else
{
//Normal colors on display
hPen =CreatePen(PS_SOLID, 0, GetSysColor(COLOR_WINDOWFRAME));
hBrush=CreateSolidBrush(GetSysColor(COLOR_WINDOW));
}
hObj1=SelectObject(hDC, hPen);
hObj2=SelectObject(hDC, hBrush);
//Paper boundary
Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom+1);
/*
* Draw a shadow on the *visual* bottom and right edges .5mm wide.
* If the button shadow color and workspace colors match, then
* use black. We always use black when printing as well.
*/
if (fNoColor)
cr=RGB(0,0,0);
else
{
cr=GetSysColor(COLOR_BTNSHADOW);
if (GetSysColor(COLOR_APPWORKSPACE)==cr)
cr=RGB(0,0,0);
}
cr=SetBkColor(hDC, cr);
SetRect(&rcT, rc.left+5, rc.bottom, rc.right+5, rc.bottom-5);
ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rcT, NULL, 0, NULL);
SetRect(&rcT, rc.right, rc.top-5, rc.right+5, rc.bottom-5);
ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rcT, NULL, 0, NULL);
SetBkColor(hDC, cr);
SelectObject(hDC, hObj1);
SelectObject(hDC, hObj2);
DeleteObject(hBrush);
DeleteObject(hPen);
}
//Write the page number in the lower left corner
if (!fNoColor)
{
SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
SetBkColor(hDC, GetSysColor(COLOR_WINDOW));
}
//Write the page number in our page font.
cch=wsprintf(szTemp, "Page %d", m_iPageCur+1);
hObj1=SelectObject(hDC, m_hFont);
dwExt=GetTextExtent(hDC, szTemp, cch);
TextOut(hDC, rc.left+m_xMarginLeft
, rc.bottom+m_yMarginBottom+HIWORD(dwExt), szTemp, cch);
SelectObject(hDC, hObj1);
//Rectangle to show border.
MoveTo(hDC, rc.left+m_xMarginLeft, rc.top-m_yMarginTop);
LineTo(hDC, rc.left+m_xMarginLeft, rc.bottom+m_yMarginBottom);
LineTo(hDC, rc.right-m_xMarginRight, rc.bottom+m_yMarginBottom);
LineTo(hDC, rc.right-m_xMarginRight, rc.top-m_yMarginTop);
LineTo(hDC, rc.left+m_xMarginLeft, rc.top-m_yMarginTop);
SetMapMode(hDC, uMM);
return;
}
/*
* CPages::UpdateScrollRanges
*
* Purpose:
* Reset scrollbar ranges (horizontal and vertical) depending on
* the window size and the page size. This function may remove the
* scrollbars altogether.
*
* Parameters:
* None, but set m_cx, m_cy and size m_hWnd before calling.
*
* Return Value:
* None
*/
void CPages::UpdateScrollRanges(void)
{
UINT cxSB; //Scrollbar width and height.
UINT